package com.nb.controller;

import com.nb.dto.CreateOrUpdateAclDTO;
import com.nb.entity.SysAclEntity;
import com.nb.result.Result;
import com.nb.service.ISysAclService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/acl")
public class AclControlller {

    @Autowired
    private ISysAclService iSysAclService;

    /**
     * 创建权限
     * @param createOrUpdateAclDTO
     * @return
     */
    @PostMapping("/create")
    public Result create(@RequestBody CreateOrUpdateAclDTO createOrUpdateAclDTO){

        iSysAclService.createAcl(createOrUpdateAclDTO);
        return Result.success();

    }

    /**
     * 更新权限
     * @param createOrUpdateAclDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody CreateOrUpdateAclDTO createOrUpdateAclDTO) {
        iSysAclService.updateAcl(createOrUpdateAclDTO);
        return Result.success();
    }

    /**
     * 删除权限
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        iSysAclService.removeById(id);
        return Result.success();
    }

    /**
     * 查询权限
     * @param name
     * @return
     */
    @GetMapping("/list")
    public Result query(@RequestParam(required = false) String name) {
        List<SysAclEntity> list = iSysAclService.queryByName(name);
        return Result.success(list);

    }

    /**
     * 查询详细
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable Long id) {
        SysAclEntity sysAclEntity = iSysAclService.getById(id);
        return Result.success(sysAclEntity);
    }




}